// 筛选值
export const ReturnSelectOptions =  (data:any, value: any)=>{
    const {
        check_role, //检查规则
        create_user, //创建人
        ctrl_scope, //控制范围
        object_type, //对象类型
        org_list, //授信组织
        currency, //币别
    } = data

    if (value == 'check_role_id' && check_role) {
        return check_role.map((item:any)=>{
            return { value: `${item.id}`, label: item.label }
        })
    }
    if (value == 'create_user_id' && create_user) {
        return create_user.map((item:any)=>{
            return { value: `${item.create_user_id}`, label: item.create_user_name }
        })
    }

    if (value == 'ctrl_scope' && ctrl_scope) {
        return ctrl_scope.map((item:any)=>{
            return { value: `${item.id}`, label: item.name }
        })
    }
    if (value == 'object_type' && object_type) {
        return object_type.map((item:any)=>{
            return { value: `${item.id}`, label: item.name }
        })
    }
    if (value == 'org_id' && org_list) {
        return org_list.map((item:any)=>{
            return { value: `${item.uid}`, label: item.name }
        })
    }
    if (value == 'currency_id' && currency) {
        return currency.map((item:any)=>{
            return { value: `${item.uid}`, label: item.name }
        })
    }
    if (value == 'credit_status') {
        return [
            { value: 1 , label: '正常检查' },
            { value: 2 , label: '信用冻结' },
            { value: 3 , label: '信用免检' },
        ]
    }
    if (value == 'status') {
        return [
            // { value: 0, label: '草稿' },
            // { value: 1, label: '待审核' },
            { value: 2, label: '已审核' },
            { value: 4, label: '额度变更中' },
            { value: 5, label: '额度变更成功' },
            { value: 6, label: '额度变更失败' },
            { value: 11, label: '临时额度待审核' },
            { value: 12, label: '临时额度已审核' },
            { value: 13, label: '临时额度审核拒绝' },
            // { value: 3, label: '审核拒绝' },
            // { value: 8, label: '已停用' },
        ]

    }
    return []
}

// 单据状态tag_color
export const StatusColor:any = (value:string | number, isColor = false)=>{
    value = value.toString()
    // 颜色
    if (isColor) {
        if (value == '0') return 'warning'
        if (value == '1') return ''
        if (value == '3') return 'danger'
        return 'info'
    }
    // 字段
    if (value == '0') return '草稿'
    if (value == '1') return '待审核'
    if (value == '3') return '审核拒绝'
    return '--'
}
// 信用状态tag_color
export const creditStatusColor:any = (value:string | Number)=>{

    let obj = {}

    // 失败、拒绝、停用 danger
    // 成功 success
    // 待 ''
    switch (value) {
        case 0:
            obj = {  label: '草稿', type: 'warning' }
            break;
        case 1:
            obj = {  label: '待审核', type: '' }
            break;
        case 2:
            obj = {  label: '已审核', type: 'success' }
            break;
        case 3:
            obj = {  label: '审核拒绝', type: 'danger' }
            break;
        case 4:
            obj = {  label: '额度变更中', type: '' }
            break;
        case 5:
            obj = {  label: '额度变更成功', type: 'success' }
            break;
        case 6:
            obj = {  label: '额度变更失败', type: 'danger' }
            break;
        case 8:
            obj = {  label: '已停用', type: 'danger' }
            break;
        case 11:
            obj = {  label: '临时额度待审核', type: '' }
            break;
        case 12:
            obj = {  label: '临时额度已审核', type: 'success' }
            break;
        case 13:
            obj = {  label: '临时额度审核拒绝', type: 'danger' }
            break;
        default:
            obj = {  label: '--', type: 'info' }
            break;
    }

    return obj
}

/**
 * @草稿箱
 */
export const DraftSearch = [
    // {  label: '授信组织', prop: 'org_id', type: 'select', multiple: false },
    {  label: '信用对象', prop: 'customer_number', type: 'lazySelect', multiple: false, lazyType: 1 },
    {  label: '信用编号', prop: 'bill_no', type: 'lazySelect', multiple: false, lazyType: 3 },
]

export const DraftCloums = [
    {  label: '授信组织', prop: 'org_name', type: '', width: '240' },
    {  label: '单据号', prop: 'bill_no', type: 'custom', width: '140'},
    {  label: '单据状态', prop: 'status', type: 'custom', width: '140'},
    {  label: '创建人', prop: 'create_user_name', type: '', width: '100' },
    {  label: '创建时间', prop: 'created_at', type: '', width: '160' },
    {  label: '授信对象', prop: 'customer_name', type: '', },
]

/**
 * @客户信用档案
 */


export const CustomSearch = [
  {  label: '客户编码', prop: 'customer_number', type: 'lazySelect', apiType: 1, dataType: 'customer_number'},
  {  label: '信用对象', prop: 'customer_name', type: 'lazySelect', apiType: 1, dataType: 'customer_name' },
  {  label: '对象类型', prop: 'object_type', type: 'select', },
  {  label: '信用编号', prop: 'bill_no', type: 'lazySelect', apiType: 2, dataType: 'bill_no' },
  {  label: '状态', prop: 'status', type: 'select', },
  {  label: '创建人', prop: 'create_user_id', type: 'select', },
]

export const CustomCloums = [
    // { label: '信用对象', prop: 'customer_name', width: '220', fixed: 'left' },
    { label: '客户编号', prop: 'customer_number', width: '120' },
    { label: '信用编号', prop: 'bill_no', width: '140', type: 'custom'},
    // { label: '授信组织', prop: 'org_name', width: '240' },
    { label: '币别', prop: 'currency_name', width: '80' },
    { label: '状态', prop: 'status', width: '140', type: 'custom' },
    { label: '固定信用额度', prop: 'credit_amount', width: '140', type: 'custom', iseye: true  },
    { label: '临时信用额度', prop: 'temp_credit_amount', width: '140', type: 'custom'  },
    // { label: '临时额度生效状态', prop: 'temp_status', width: '140', type: '' },
    // { label: '临时额度有效期', prop: 'expiry_date', width: '220', type: 'custom', iseye: false  },
    { label: '已使用额度', prop: 'use_credit_amount', width: '120', type: 'custom', iseye: true   },
    { label: '额度余额', prop: 'residue_credit_amount', width: '140', type: 'custom', iseye: true   },
    { label: '额度逾期', prop: 'over_amount', width: '100', type: ''  },
    { label: '额度逾期天数', prop: 'over_day', width: '120', type: 'number', iseye: false   },
    { label: '逾期比例', prop: 'over_rate', width: '100', type: ''  },
    { label: '检查规则', prop: 'check_role_name', width: '160', type: ''  },
    { label: '创建人', prop: 'create_user_name', width: '80', type: ''  },
    { label: '创建时间', prop: 'created_at', width: '160', type: ''  },
    { label: '审核人', prop: 'approve_user_name', width: '80', type: ''  },
    { label: '审核时间', prop: 'approve_date', width: '160', type: ''  },
    { label: '最后更新人', prop: 'update_user_name', width: '100', type: ''  },
    { label: '更新时间', prop: 'updated_at', width: '160', type: ''  },
]

/**
 * @客户价目表创建
 */

export const CreateBaseForm = [
    {  label: '控制范围', prop: 'ctrl_scope', type: 'select', multiple: false, disabled: true},
    {  label: '授信组织', prop: 'org_id', type: 'select', multiple: false, disabled: true},
    // {  label: '信用对象范围', prop: 'object_type', type: 'select', multiple: false, disabled: false },
]
export const ScopeCloums = [
    { label: '信用对象', prop: 'customer_id' , required: true },
    { label: '客户编码', prop: 'customer_number', required: false },
    { label: '币别', prop: 'currency_id', width: '100' , required: true },
    { label: '信用额度', prop: 'credit_amount', width: '100' , required: true},
    { label: '信用状态', prop: 'credit_status', width: '140' , required: true },
    { label: '检查规则', prop: 'check_role_id', width: '140' , required: true},
]

/**
 * @草稿箱详情
 */

export const DetailBase = [
    {  label: '控制范围', prop: 'ctrl_scope_name', type: 'select', multiple: false, disabled: false},
    {  label: '授信组织', prop: 'org_name', type: 'select', multiple: false, disabled: false},
    {  label: '信用对象范围', prop: 'object_type_name', type: 'select', multiple: false, disabled: false },
]
export const DetailCloums = [
    { label: '信用对象', prop: 'customer_name' , type: '' },
    { label: '客户编码', prop: 'customer_number', required: false },
    { label: '币别', prop: 'currency_name', width: '100' , type: '' },
    { label: '信用额度', prop: 'credit_amount', width: '140' , type: 'custom'},
    { label: '信用状态', prop: 'credit_status', width: '140' , type: 'custom' },
    { label: '检查规则', prop: 'check_role_name', width: '200' , type: ''},
]

/**
 * @信用变动明细详情
 */

export const CustomDetailBase = [
    {  label: '授信组织', prop: 'org_name', type: ''},
    // {  label: '授信部门', prop: 'AAAA', type: ''},
    // {  label: '授信物料客户', prop: 'AAAA', type: ''},
    // {  label: '授信销售员', prop: 'AAAA', type: ''},
    {  label: '信用检查规则', prop: 'check_role_name', type: ''},
    {  label: '对象类型', prop: 'object_type_str', type: ''},
    {  label: '信用控制对象', prop: 'customer_name', type: ''},
    // {  label: '授信销售组', prop: 'AAAA', type: ''},
    {  label: '授信币别', prop: 'currency_name', type: ''},
    {  label: '授信额度', prop: 'credit_amount', type: '', iseye: true},
    {  label: '临时授信额度', prop: 'temp_credit_amount', type: 'money', iseye: true},
    {  label: '信用余额', prop: 'residue_credit_amount', type: 'money', iseye: true},
]
export const CustomDetailCloums = [
    { label: '业务单据', prop: 'document_str' , type: '', width: '140'  },
    { label: '单据编号', prop: 'bill_no', width: '160' },
    { label: '单据日期', prop: 'created_at', width: '160' , type: '' },
    { label: '源单名称', prop: 'source_document_str', width: '120' , type: ''},
    { label: '源单编号', prop: 'source_bill_no', width: '120' , type: '' },
    { label: '客户编码', prop: 'customer_number', width: '140' , type: ''},
    { label: '客户名称', prop: 'customer_name', width: '240' , type: ''},
    { label: '源单占用额度', prop: 'source_own_amount', width: '120' , type: 'custom', iseye: true },
    { label: '本单金额', prop: 'discount_amount', width: '120' , type: 'custom', iseye: true},
    { label: '本单净增加额度', prop: 'AAA', width: '140' , type: 'custom', iseye: true},
    { label: '收款扣减额度', prop: 'payment_amount', width: '120' , type: 'custom', iseye: true},
    { label: '手工关闭或终止释放额度', prop: 'stop_amount', width: '200' , type: 'custom', iseye: true},
    { label: '核销金额', prop: 'cancel_amount', width: '120' , type: 'custom', iseye: true},
    { label: '信用占用额度', prop: 'own_amount', width: '120' , type: 'custom', iseye: true},
    { label: '逾期天数', prop: 'over_day', width: '120' , type: 'number'},
    { label: '逾期额度', prop: 'over_amount', width: '120' , type: 'custom', iseye: true},
]


// 临时信用额度 弹窗
export const TemporaryLimitCloums = [
    { label: '临时信用额度', prop: 'credit_amount' , type: 'money', width: '120'  },
    { label: '临时额度生效状态', prop: 'effective_status_str', width: '160' },
    { label: '有效期', prop: 'date', type: '', width: '300' },
    { label: '申请人', prop: 'create_user_name', width: '100' , type: ''},
    { label: '审核状态', prop: 'status_str', width: '100' , type: ''},
    { label: '备注', prop: 'note', width: '120' , type: '' },
]
